package vertx.starter.rx;

import io.reactivex.Single;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;

/**
 * rx-java结合
 */
public class MainVerticle extends io.vertx.reactivex.core.AbstractVerticle {
    @Override
    public void start(Promise<Void> promise) throws Exception {

        Single<String> dbVerticleDeployment = vertx.rxDeployVerticle(
                "vertx.starter.rx.db.DatabaseVerticle");

        dbVerticleDeployment
                .flatMap(id -> {
                    Single<String> httpVerticleDeployment = vertx.rxDeployVerticle(
                            "vertx.starter.rx.HttpServerVerticle",
                            new DeploymentOptions().setInstances(2));

                    return httpVerticleDeployment;
                }).subscribe(id -> promise.complete(), promise::fail);
    }

}
